package com.dingyh.shopwebbackground.controller;


import com.dingyh.shopwebbackground.entity.Payouts;
import com.dingyh.shopwebbackground.service.PayoutsService;
import com.dingyh.shopwebbackground.util.CommonResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dingyuhan
 * @since 2023-02-21
 */
@RestController
@CrossOrigin
@RequestMapping("/payouts")
public class PayoutsController {

    @Autowired
    PayoutsService payoutsService;

    @RequestMapping("/getAllPayouts")
    public CommonResult<Object> getAllPayouts(@RequestParam(defaultValue = "1",required = true)int pageIndex,@RequestParam(defaultValue = "10",required = false)int pageSize){
        PageHelper.offsetPage((pageIndex - 1) * pageSize,pageSize);
        List<Payouts> payoutsList = payoutsService.getAllPayouts();
        PageInfo<Payouts> pageInfo = new PageInfo<>(payoutsList);
        return new CommonResult<>(200,"",pageInfo);
    }

    /**
     * 管理员页面折线图数据
     * @param start
     * @param end
     * @return
     */
    @RequestMapping("/getLine")
    public CommonResult<Object> getLine(Long start, Long end){
        return new CommonResult<>(200,"",payoutsService.getLine(start, end));
    }

}

